import { defineConfig } from "rollup";
import babel from "@rollup/plugin-babel";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import { terser } from "rollup-plugin-terser";
import json from "@rollup/plugin-json";
import typescript from "rollup-plugin-ts";
import rollupExternalModules from "rollup-external-modules";
import define from "rollup-plugin-define";
const plugins = [
    typescript(),
    resolve(),
    commonjs(),
    json(),
    babel({
        babelHelpers: "bundled",
        presets: ["@babel/preset-env"],
        extensions: [".js", ".ts", ".cjs"],
    }),
    define({
        replacements: {
            "process.env.browser": "false",
            "process.env.PRERENDER": "true",
        },
    }),
    terser({
        compress: { drop_console: true, drop_debugger: true },
        mangle: false,
        output: { beautify: true, comments: false },
    }),
];
export default defineConfig([
    {
        external: rollupExternalModules,
        plugins: plugins,
        input: "./prerender/index.ts",
        output: [
            {
                inlineDynamicImports: true,

                file: "./bin/prerender.js",
                format: "esm",
                sourcemap: true,
            },
        ],
    },
    {
        external: rollupExternalModules,
        plugins: plugins,
        input: "./prerender/mathjax-worker.js",
        output: [
            {
                inlineDynamicImports: true,

                file: "./bin/mathjax-worker.cjs",
                format: "cjs",
                sourcemap: true,
            },
        ],
    },
    // {
    //     external: rollupExternalModules,
    //     plugins: plugins,
    //     input: "./prerender/webpack-loader.ts",
    //     output: [
    //         {
    //             inlineDynamicImports: true,
    //             exports: "auto",
    //             file: "./bin/webpack-loader.cjs",
    //             format: "cjs",
    //             sourcemap: true,
    //         },
    //     ],
    // },
]);
